import request from 'umi-request';
import moment from 'moment';

export async function queryDimissionAuditList(params = {}) {
  let { current, hiredate, ...data} = params;
  let hiredateStart = hiredate?.length>1 ? moment(hiredate[0]).format('YYYY-MM-DD') : null;
  let hiredateEnd = hiredate?.length>1 ? moment(hiredate[1]).format('YYYY-MM-DD') : null;
  return request('/hr-ssc/api/api-admin/dimission/queryDimissionAuditList', {
    method: 'get',
    params: {
      hiredateStart,
      hiredateEnd,
      pageNum: current,
      ...data
    },
  }).then((res) => {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
  });
}

export async function saveDimissionAudit(params) {
  return request('/hr-ssc/api/api-admin/dimission/saveDimissionAudit', {
    method: 'POST',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function updateDimissionAudit(params) {
  return request('/hr-ssc/api/api-admin/dimission/updateDimissionAudit', {
    method: 'POST',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function dimissionAuditBpm(params) {
  return request('/hr-ssc/api/api-admin/bpm/dimissionAuditBpm', {
    method: 'get',
    params: params,
  }).then((res) => {
    return res;
  });
}

export async function findEmpByNameOrCode(params) {
  return request('/hr-ssc/api/api-admin/job/findEmpByNameOrCode', {
    method: 'get',
    params: params,
  }).then((res) => {
    if (res.flag){
      return res.data;
    }
    return [];
  });
}
